package com.lw.common.webview

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.lw.common.base.BaseActivity
import com.lw.common.databinding.ActivityWebviewBinding

/**
 * @description:网页
 * @author: yuan
 * @date: 2024/12/16
 */
class WebViewActivity : BaseActivity<ActivityWebviewBinding>(), View.OnClickListener {
    @SuppressLint("SetJavaScriptEnabled")
    override fun initView(savedInstanceState: Bundle?) {
//        MyThemeUtil.setTheme(this, binding.toolbar.toolbar);
        val type = intent.getStringExtra("type")
        mBinding.toolbar.toolbar.setNavigationOnClickListener { finish() }
        mBinding.toolbar.toolbarMenu.visibility = View.GONE
        if (type == "用户协议") {
            //用户协议
            mBinding.toolbar.toolbarTitle.text = "用户协议"
            mBinding.webView.loadUrl("http://114.215.29.22:8080/软件用户协议.txt")
        } else {
            //隐私政策
            mBinding.toolbar.toolbarTitle.text = "隐私权政策"
            mBinding.webView.loadUrl("http://114.215.29.22:8080/隐私声明.txt")
        }
        mBinding.webView.settings.javaScriptEnabled = true
    }

    override fun onClick(view: View) {
        finish()
    }


    override fun onPause() {
        mBinding.webView.onPause()
        super.onPause()
    }

    override fun onResume() {
        mBinding.webView.onResume()
        super.onResume()
    }

    companion object {
        fun start(context: Context, type: String?) {
            val intent = Intent(context, WebViewActivity::class.java)
            intent.putExtra("type", type)
            context.startActivity(intent)
        }
    }
}
